home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / usr_-_Usr_Files / BIN / H2PH < prev    next >
Text File  |  1999-09-17  |  19KB  |  695 lines

  1. #!/usr/bin/perl
  2.     eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
  3.     if $running_under_some_shell;
  4.  
  5. use Config;
  6. use File::Path qw(mkpath);
  7. use Getopt::Std;
  8.  
  9. getopts('Dd:rlhaQ');
  10. die "-r and -a options are mutually exclusive\n" if ($opt_r and $opt_a);
  11. @inc_dirs = inc_dirs() if $opt_a;
  12.  
  13. my $Exit = 0;
  14.  
  15. my $Dest_dir = $opt_d || $Config{installsitearch};
  16. die "Destination directory $Dest_dir doesn't exist or isn't a directory\n"
  17.     unless -d $Dest_dir;
  18.  
  19. @isatype = split(' ',<<END);
  20.     char    uchar    u_char
  21.     short    ushort    u_short
  22.     int    uint    u_int
  23.     long    ulong    u_long
  24.     FILE    key_t    caddr_t
  25. END
  26.  
  27. @isatype{@isatype} = (1) x @isatype;
  28. $inif = 0;
  29.  
  30. @ARGV = ('-') unless @ARGV;
  31.  
  32. build_preamble_if_necessary();
  33.  
  34. while (defined ($file = next_file())) {
  35.     if (-l $file and -d $file) {
  36.         link_if_possible($file) if ($opt_l);
  37.         next;
  38.     }
  39.  
  40.     # Recover from header files with unbalanced cpp directives
  41.     $t = '';
  42.     $tab = 0;
  43.  
  44.     # $eval_index goes into ``#line'' directives, to help locate syntax errors:
  45.     $eval_index = 1;
  46.  
  47.     if ($file eq '-') {
  48.     open(IN, "-");
  49.     open(OUT, ">-");
  50.     } else {
  51.     ($outfile = $file) =~ s/\.h$/.ph/ || next;
  52.     print "$file -> $outfile\n" unless $opt_Q;
  53.     if ($file =~ m|^(.*)/|) {
  54.         $dir = $1;
  55.         mkpath "$Dest_dir/$dir";
  56.     }
  57.  
  58.     if ($opt_a) { # automagic mode:  locate header file in @inc_dirs
  59.         foreach (@inc_dirs) {
  60.         chdir $_;
  61.         last if -f $file;
  62.         }
  63.     }
  64.  
  65.     open(IN,"$file") || (($Exit = 1),(warn "Can't open $file: $!\n"),next);
  66.     open(OUT,">$Dest_dir/$outfile") || die "Can't create $outfile: $!\n";
  67.     }
  68.  
  69.     print OUT "require '_h2ph_pre.ph';\n\n";
  70.     while (<IN>) {
  71.     chop;
  72.     while (/\\$/) {
  73.         chop;
  74.         $_ .= <IN>;
  75.         chop;
  76.     }
  77.     print OUT "# $_\n" if $opt_D;
  78.  
  79.     if (s:/\*:\200:g) {
  80.         s:\*/:\201:g;
  81.         s/\200[^\201]*\201//g;    # delete single line comments
  82.         if (s/\200.*//) {        # begin multi-line comment?
  83.         $_ .= '/*';
  84.         $_ .= <IN>;
  85.         redo;
  86.         }
  87.     }
  88.     if (s/^\s*\#\s*//) {
  89.         if (s/^define\s+(\w+)//) {
  90.         $name = $1;
  91.         $new = '';
  92.         s/\s+$//;
  93.         if (s/^\(([\w,\s]*)\)//) {
  94.             $args = $1;
  95.                     my $proto = '() ';
  96.             if ($args ne '') {
  97.                         $proto = '';
  98.             foreach $arg (split(/,\s*/,$args)) {
  99.                 $arg =~ s/^\s*([^\s].*[^\s])\s*$/$1/;
  100.                 $curargs{$arg} = 1;
  101.             }
  102.             $args =~ s/\b(\w)/\$$1/g;
  103.             $args = "local($args) = \@_;\n$t    ";
  104.             }
  105.             s/^\s+//;
  106.             expr();
  107.             $new =~ s/(["\\])/\\$1/g;       #"]);
  108.             $new = reindent($new);
  109.             $args = reindent($args);
  110.             if ($t ne '') {
  111.             $new =~ s/(['\\])/\\$1/g;   #']);
  112.             if ($opt_h) {
  113.                 print OUT $t,
  114.                             "eval \"\\n#line $eval_index $outfile\\n\" . 'sub $name $proto\{\n$t    ${args}eval q($new);\n$t}' unless defined(\&$name);\n";
  115.                             $eval_index++;
  116.             } else {
  117.                 print OUT $t,
  118.                             "eval 'sub $name $proto\{\n$t    ${args}eval q($new);\n$t}' unless defined(\&$name);\n";
  119.             }
  120.             } else {
  121.                       print OUT "unless(defined(\&$name)) {\n    sub $name $proto\{\n\t${args}eval q($new);\n    }\n}\n";
  122.             }
  123.             %curargs = ();
  124.         } else {
  125.             s/^\s+//;
  126.             expr();
  127.             $new = 1 if $new eq '';
  128.             $new = reindent($new);
  129.             $args = reindent($args);
  130.             if ($t ne '') {
  131.             $new =~ s/(['\\])/\\$1/g;        #']);
  132.  
  133.             if ($opt_h) {
  134.                 print OUT $t,"eval \"\\n#line $eval_index $outfile\\n\" . 'sub $name () {",$new,";}' unless defined(\&$name);\n";
  135.                 $eval_index++;
  136.             } else {
  137.                 print OUT $t,"eval 'sub $name () {",$new,";}' unless defined(\&$name);\n";
  138.             }
  139.             } else {
  140.                 # Shunt around such directives as `#define FOO FOO':
  141.                 next if " \&$name" eq $new;
  142.  
  143.                       print OUT $t,"unless(defined(\&$name)) {\n    sub $name () {\t",$new,";}\n}\n";
  144.             }
  145.         }
  146.         } elsif (/^(include|import)\s*[<"](.*)[>"]/) {
  147.         ($incl = $2) =~ s/\.h$/.ph/;
  148.         print OUT $t,"require '$incl';\n";
  149.         } elsif(/^include_next\s*[<"](.*)[>"]/) {
  150.         ($incl = $1) =~ s/\.h$/.ph/;
  151.         print OUT ($t,
  152.                "eval {\n");
  153.                 $tab += 4;
  154.                 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
  155.         print OUT ($t,
  156.                "my(\%INCD) = map { \$INC{\$_} => 1 } ",
  157.                "(grep { \$_ eq \"$incl\" } keys(\%INC));\n");
  158.         print OUT ($t,
  159.                "my(\@REM) = map { \"\$_/$incl\" } ",
  160.                "(grep { not exists(\$INCD{\"\$_/$incl\"})",
  161.                "and -f \"\$_/$incl\" } \@INC);\n");
  162.         print OUT ($t,
  163.                "require \"\$REM[0]\" if \@REM;\n");
  164.                 $tab -= 4;
  165.                 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
  166.                 print OUT ($t,
  167.                "};\n");
  168.         print OUT ($t,
  169.                "warn(\$\@) if \$\@;\n");
  170.         } elsif (/^ifdef\s+(\w+)/) {
  171.         print OUT $t,"if(defined(&$1)) {\n";
  172.         $tab += 4;
  173.         $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
  174.         } elsif (/^ifndef\s+(\w+)/) {
  175.         print OUT $t,"unless(defined(&$1)) {\n";
  176.         $tab += 4;
  177.         $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
  178.         } elsif (s/^if\s+//) {
  179.         $new = '';
  180.         $inif = 1;
  181.         expr();
  182.         $inif = 0;
  183.         print OUT $t,"if($new) {\n";
  184.         $tab += 4;
  185.         $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
  186.         } elsif (s/^elif\s+//) {
  187.         $new = '';
  188.         $inif = 1;
  189.         expr();
  190.         $inif = 0;
  191.         $tab -= 4;
  192.         $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
  193.         print OUT $t,"}\n elsif($new) {\n";
  194.         $tab += 4;
  195.         $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
  196.         } elsif (/^else/) {
  197.         $tab -= 4;
  198.         $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
  199.         print OUT $t,"} else {\n";
  200.         $tab += 4;
  201.         $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
  202.         } elsif (/^endif/) {
  203.         $tab -= 4;
  204.         $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
  205.         print OUT $t,"}\n";
  206.         } elsif(/^undef\s+(\w+)/) {
  207.         print OUT $t, "undef(&$1) if defined(&$1);\n";
  208.         } elsif(/^error\s+(".*")/) {
  209.         print OUT $t, "die($1);\n";
  210.         } elsif(/^error\s+(.*)/) {
  211.         print OUT $t, "die(\"", quotemeta($1), "\");\n";
  212.         } elsif(/^warning\s+(.*)/) {
  213.         print OUT $t, "warn(\"", quotemeta($1), "\");\n";
  214.         } elsif(/^ident\s+(.*)/) {
  215.         print OUT $t, "# $1\n";
  216.         }
  217.      } elsif(/^\s*(typedef\s*)?enum\s*(\s+[a-zA-Z_]\w*\s*)?\{/) {
  218.         until(/\}.*?;/) {
  219.         chomp($next = <IN>);
  220.         $_ .= $next;
  221.         print OUT "# $next\n" if $opt_D;
  222.         }
  223.         s@/\*.*?\*/@@g;
  224.         s/\s+/ /g;
  225.         /^\s?(typedef\s?)?enum\s?([a-zA-Z_]\w*)?\s?\{(.*)\}\s?([a-zA-Z_]\w*)?\s?;/;
  226.         ($enum_subs = $3) =~ s/\s//g;
  227.         @enum_subs = split(/,/, $enum_subs);
  228.         $enum_val = -1;
  229.         for $enum (@enum_subs) {
  230.         ($enum_name, $enum_value) = $enum =~ /^([a-zA-Z_]\w*)(=.+)?$/;
  231.         $enum_value =~ s/^=//;
  232.         $enum_val = (length($enum_value) ? $enum_value : $enum_val + 1);
  233.         if ($opt_h) {
  234.             print OUT ($t,
  235.                    "eval(\"\\n#line $eval_index $outfile\\n",
  236.                    "sub $enum_name () \{ $enum_val; \}\") ",
  237.                    "unless defined(\&$enum_name);\n");
  238.             ++ $eval_index;
  239.         } else {
  240.             print OUT ($t,
  241.                    "eval(\"sub $enum_name () \{ $enum_val; \}\") ",
  242.                    "unless defined(\&$enum_name);\n");
  243.         }
  244.         }
  245.     }
  246.     }
  247.     print OUT "1;\n";
  248.  
  249.     $is_converted{$file} = 1;
  250.     queue_includes_from($file) if ($opt_a);
  251. }
  252.  
  253. exit $Exit;
  254.  
  255. sub reindent($) {
  256.     my($text) = shift;
  257.     $text =~ s/\n/\n    /g;
  258.     $text =~ s/        /\t/g;
  259.     $text;
  260. }
  261.  
  262. sub expr {
  263.     if(keys(%curargs)) {
  264.     my($joined_args) = join('|', keys(%curargs));
  265.     }
  266.     while ($_ ne '') {
  267.     s/^\&\&// && do { $new .= " &&"; next;}; # handle && operator
  268.     s/^\&([\(a-z\)]+)/$1/i;    # hack for things that take the address of
  269.     s/^(\s+)//        && do {$new .= ' '; next;};
  270.     s/^(0X[0-9A-F]+)[UL]*//i    && do {$new .= lc($1); next;};
  271.     s/^(-?\d+\.\d+E[-+]\d+)F?//i    && do {$new .= $1; next;};
  272.     s/^(\d+)\s*[LU]*//i    && do {$new .= $1; next;};
  273.     s/^("(\\"|[^"])*")//    && do {$new .= $1; next;};
  274.     s/^'((\\"|[^"])*)'//    && do {
  275.         if ($curargs{$1}) {
  276.         $new .= "ord('\$$1')";
  277.         } else {
  278.         $new .= "ord('$1')";
  279.         }
  280.         next;
  281.     };
  282.         # replace "sizeof(foo)" with "{foo}"
  283.         # also, remove * (C dereference operator) to avoid perl syntax
  284.         # problems.  Where the %sizeof array comes from is anyone's
  285.         # guess (c2ph?), but this at least avoids fatal syntax errors.
  286.         # Behavior is undefined if sizeof() delimiters are unbalanced.
  287.         # This code was modified to able to handle constructs like this:
  288.         #   sizeof(*(p)), which appear in the HP-UX 10.01 header files.
  289.         s/^sizeof\s*\(// && do {
  290.             $new .= '$sizeof';
  291.             my $lvl = 1;  # already saw one open paren
  292.             # tack { on the front, and skip it in the loop
  293.             $_ = "{" . "$_";
  294.             my $index = 1;
  295.             # find balanced closing paren
  296.             while ($index <= length($_) && $lvl > 0) {
  297.                 $lvl++ if substr($_, $index, 1) eq "(";
  298.                 $lvl-- if substr($_, $index, 1) eq ")";
  299.                 $index++;
  300.             }
  301.             # tack } on the end, replacing )
  302.             substr($_, $index - 1, 1) = "}";
  303.             # remove pesky * operators within the sizeof argument
  304.             substr($_, 0, $index - 1) =~ s/\*//g;
  305.             next;
  306.         };
  307.     # Eliminate typedefs
  308.     /\(([\w\s]+)[\*\s]*\)\s*[\w\(]/ && do {
  309.         foreach (split /\s+/, $1) {  # Make sure all the words are types,
  310.         last unless ($isatype{$_} or $_ eq 'struct');
  311.         }
  312.         s/\([\w\s]+[\*\s]*\)// && next;      # then eliminate them.
  313.     };
  314.     # struct/union member, including arrays:
  315.     s/^([_A-Z]\w*(\[[^\]]+\])?((\.|->)[_A-Z]\w*(\[[^\]]+\])?)+)//i && do {
  316.         $id = $1;
  317.         $id =~ s/(\.|(->))([^\.\-]*)/->\{$3\}/g;
  318.         $id =~ s/\b([^\$])($joined_args)/$1\$$2/g if length($joined_args);
  319.         while($id =~ /\[\s*([^\$\&\d\]]+)\]/) {
  320.         my($index) = $1;
  321.         $index =~ s/\s//g;
  322.         if(exists($curargs{$index})) {
  323.             $index = "\$$index";
  324.         } else {
  325.             $index = "&$index";
  326.         }
  327.         $id =~ s/\[\s*([^\$\&\d\]]+)\]/[$index]/;
  328.         }
  329.         $new .= " (\$$id)";
  330.     };
  331.     s/^([_a-zA-Z]\w*)//    && do {
  332.         $id = $1;
  333.         if ($id eq 'struct') {
  334.         s/^\s+(\w+)//;
  335.         $id .= ' ' . $1;
  336.         $isatype{$id} = 1;
  337.         } elsif ($id =~ /^((un)?signed)|(long)|(short)$/) {
  338.         while (s/^\s+(\w+)//) { $id .= ' ' . $1; }
  339.         $isatype{$id} = 1;
  340.         }
  341.         if ($curargs{$id}) {
  342.         $new .= "\$$id";
  343.         $new .= '->' if /^[\[\{]/;
  344.         } elsif ($id eq 'defined') {
  345.         $new .= 'defined';
  346.         } elsif (/^\(/) {
  347.         s/^\((\w),/("$1",/ if $id =~ /^_IO[WR]*$/i;    # cheat
  348.         $new .= " &$id";
  349.         } elsif ($isatype{$id}) {
  350.         if ($new =~ /{\s*$/) {
  351.             $new .= "'$id'";
  352.         } elsif ($new =~ /\(\s*$/ && /^[\s*]*\)/) {
  353.             $new =~ s/\(\s*$//;
  354.             s/^[\s*]*\)//;
  355.         } else {
  356.             $new .= q(').$id.q(');
  357.         }
  358.         } else {
  359.         if ($inif && $new !~ /defined\s*\($/) {
  360.             $new .= '(defined(&' . $id . ') ? &' . $id . ' : 0)';
  361.         } elsif (/^\[/) {
  362.             $new .= " \$$id";
  363.         } else {
  364.             $new .= ' &' . $id;
  365.         }
  366.         }
  367.         next;
  368.     };
  369.     s/^(.)// && do { if ($1 ne '#') { $new .= $1; } next;};
  370.     }
  371. }
  372.  
  373.  
  374. # Handle recursive subdirectories without getting a grotesquely big stack.
  375. # Could this be implemented using File::Find?
  376. sub next_file
  377. {
  378.     my $file;
  379.  
  380.     while (@ARGV) {
  381.         $file = shift @ARGV;
  382.  
  383.         if ($file eq '-' or -f $file or -l $file) {
  384.             return $file;
  385.         } elsif (-d $file) {
  386.             if ($opt_r) {
  387.                 expand_glob($file);
  388.             } else {
  389.                 print STDERR "Skipping directory `$file'\n";
  390.             }
  391.         } elsif ($opt_a) {
  392.             return $file;
  393.         } else {
  394.             print STDERR "Skipping `$file':  not a file or directory\n";
  395.         }
  396.     }
  397.  
  398.     return undef;
  399. }
  400.  
  401.  
  402. # Put all the files in $directory into @ARGV for processing.
  403. sub expand_glob
  404. {
  405.     my ($directory)  = @_;
  406.  
  407.     $directory =~ s:/$::;
  408.  
  409.     opendir DIR, $directory;
  410.         foreach (readdir DIR) {
  411.             next if ($_ eq '.' or $_ eq '..');
  412.  
  413.             # expand_glob() is going to be called until $ARGV[0] isn't a
  414.             # directory; so push directories, and unshift everything else.
  415.             if (-d "$directory/$_") { push    @ARGV, "$directory/$_" }
  416.             else                    { unshift @ARGV, "$directory/$_" }
  417.         }
  418.     closedir DIR;
  419. }
  420.  
  421.  
  422. # Given $file, a symbolic link to a directory in the C include directory,
  423. # make an equivalent symbolic link in $Dest_dir, if we can figure out how.
  424. # Otherwise, just duplicate the file or directory.
  425. sub link_if_possible
  426. {
  427.     my ($dirlink)  = @_;
  428.     my $target  = eval 'readlink($dirlink)';
  429.  
  430.     if ($target =~ m:^\.\./: or $target =~ m:^/:) {
  431.         # The target of a parent or absolute link could leave the $Dest_dir
  432.         # hierarchy, so let's put all of the contents of $dirlink (actually,
  433.         # the contents of $target) into @ARGV; as a side effect down the
  434.         # line, $dirlink will get created as an _actual_ directory.
  435.         expand_glob($dirlink);
  436.     } else {
  437.         if (-l "$Dest_dir/$dirlink") {
  438.             unlink "$Dest_dir/$dirlink" or
  439.                 print STDERR "Could not remove link $Dest_dir/$dirlink:  $!\n";
  440.         }
  441.  
  442.         if (eval 'symlink($target, "$Dest_dir/$dirlink")') {
  443.             print "Linking $target -> $Dest_dir/$dirlink\n";
  444.  
  445.             # Make sure that the link _links_ to something:
  446.             if (! -e "$Dest_dir/$target") {
  447.                 mkpath("$Dest_dir/$target", 0755) or
  448.                     print STDERR "Could not create $Dest_dir/$target/\n";
  449.             }
  450.         } else {
  451.             print STDERR "Could not symlink $target -> $Dest_dir/$dirlink:  $!\n";
  452.         }
  453.     }
  454. }
  455.  
  456.  
  457. # Push all #included files in $file onto our stack, except for STDIN
  458. # and files we've already processed.
  459. sub queue_includes_from
  460. {
  461.     my ($file)    = @_;
  462.     my $line;
  463.  
  464.     return if ($file eq "-");
  465.  
  466.     open HEADER, $file or return;
  467.         while (defined($line = <HEADER>)) {
  468.             while (/\\$/) { # Handle continuation lines
  469.                 chop $line;
  470.                 $line .= <HEADER>;
  471.             }
  472.  
  473.             if ($line =~ /^#\s*include\s+<(.*?)>/) {
  474.                 push(@ARGV, $1) unless $is_converted{$1};
  475.             }
  476.         }
  477.     close HEADER;
  478. }
  479.  
  480.  
  481. # Determine include directories; $Config{usrinc} should be enough for (all
  482. # non-GCC?) C compilers, but gcc uses an additional include directory.
  483. sub inc_dirs
  484. {
  485.     my $from_gcc    = `$Config{cc} -v 2>&1`;
  486.     $from_gcc       =~ s:^Reading specs from (.*?)/specs\b.*:$1/include:s;
  487.  
  488.     length($from_gcc) ? ($from_gcc, $Config{usrinc}) : ($Config{usrinc});
  489. }
  490.  
  491.  
  492. # Create "_h2ph_pre.ph", if it doesn't exist or was built by a different
  493. # version of h2ph.
  494. sub build_preamble_if_necessary
  495. {
  496.     # Increment $VERSION every time this function is modified:
  497.     my $VERSION     = 1;
  498.     my $preamble    = "$Dest_dir/_h2ph_pre.ph";
  499.  
  500.     # Can we skip building the preamble file?
  501.     if (-r $preamble) {
  502.         # Extract version number from first line of preamble:
  503.         open  PREAMBLE, $preamble or die "Cannot open $preamble:  $!";
  504.             my $line = <PREAMBLE>;
  505.             $line =~ /(\b\d+\b)/;
  506.         close PREAMBLE            or die "Cannot close $preamble:  $!";
  507.  
  508.         # Don't build preamble if a compatible preamble exists:
  509.         return if $1 == $VERSION;
  510.     }
  511.  
  512.     my (%define) = _extract_cc_defines();
  513.  
  514.     open  PREAMBLE, ">$preamble" or die "Cannot open $preamble:  $!";
  515.         print PREAMBLE "# This file was created by h2ph version $VERSION\n";
  516.  
  517.         foreach (sort keys %define) {
  518.             if ($opt_D) {
  519.                 print PREAMBLE "# $_=$define{$_}\n";
  520.             }
  521.  
  522.             if ($define{$_} =~ /^\d+$/) {
  523.                 print PREAMBLE
  524.                     "unless (defined &$_) { sub $_() { $define{$_} } }\n\n";
  525.             } else {
  526.                 print PREAMBLE
  527.                     "unless (defined &$_) { sub $_() { \"",
  528.                     quotemeta($define{$_}), "\" } }\n\n";
  529.             }
  530.         }
  531.     close PREAMBLE               or die "Cannot close $preamble:  $!";
  532. }
  533.  
  534.  
  535. # %Config contains information on macros that are pre-defined by the
  536. # system's compiler.  We need this information to make the .ph files
  537. # function with perl as the .h files do with cc.
  538. sub _extract_cc_defines
  539. {
  540.     my %define;
  541.     my $allsymbols = join " ", @Config{ccsymbols, cppsymbols, cppccsymbols};
  542.  
  543.     # Split compiler pre-definitions into `key=value' pairs:
  544.     foreach (split /\s+/, $allsymbols) {
  545.         /(.*?)=(.*)/;
  546.         $define{$1} = $2;
  547.  
  548.         if ($opt_D) {
  549.             print STDERR "$_:  $1 -> $2\n";
  550.         }
  551.     }
  552.  
  553.     return %define;
  554. }
  555.  
  556.  
  557. 1;
  558.  
  559. ##############################################################################
  560. __END__
  561.  
  562. =head1 NAME
  563.  
  564. h2ph - convert .h C header files to .ph Perl header files
  565.  
  566. =head1 SYNOPSIS
  567.  
  568. B<h2ph [-d destination directory] [-r | -a] [-l] [headerfiles]>
  569.  
  570. =head1 DESCRIPTION
  571.  
  572. I<h2ph>
  573. converts any C header files specified to the corresponding Perl header file
  574. format.
  575. It is most easily run while in /usr/include:
  576.  
  577.     cd /usr/include; h2ph * sys/*
  578.  
  579. or
  580.  
  581.     cd /usr/include; h2ph -r -l .
  582.  
  583. The output files are placed in the hierarchy rooted at Perl's
  584. architecture dependent library directory.  You can specify a different
  585. hierarchy with a B<-d> switch.
  586.  
  587. If run with no arguments, filters standard input to standard output.
  588.  
  589. =head1 OPTIONS
  590.  
  591. =over 4
  592.  
  593. =item -d destination_dir
  594.  
  595. Put the resulting B<.ph> files beneath B<destination_dir>, instead of
  596. beneath the default Perl library location (C<$Config{'installsitsearch'}>).
  597.  
  598. =item -r
  599.  
  600. Run recursively; if any of B<headerfiles> are directories, then run I<h2ph>
  601. on all files in those directories (and their subdirectories, etc.).  B<-r>
  602. and B<-a> are mutually exclusive.
  603.  
  604. =item -a
  605.  
  606. Run automagically; convert B<headerfiles>, as well as any B<.h> files
  607. which they include.  This option will search for B<.h> files in all
  608. directories which your C compiler ordinarily uses.  B<-a> and B<-r> are
  609. mutually exclusive.
  610.  
  611. =item -l
  612.  
  613. Symbolic links will be replicated in the destination directory.  If B<-l>
  614. is not specified, then links are skipped over.
  615.  
  616. =item -h
  617.  
  618. Put ``hints'' in the .ph files which will help in locating problems with
  619. I<h2ph>.  In those cases when you B<require> a B<.ph> file containing syntax
  620. errors, instead of the cryptic
  621.  
  622.     [ some error condition ] at (eval mmm) line nnn
  623.  
  624. you will see the slightly more helpful
  625.  
  626.     [ some error condition ] at filename.ph line nnn
  627.  
  628. However, the B<.ph> files almost double in size when built using B<-h>.
  629.  
  630. =item -D
  631.  
  632. Include the code from the B<.h> file as a comment in the B<.ph> file.
  633. This is primarily used for debugging I<h2ph>.
  634.  
  635. =item -Q
  636.  
  637. ``Quiet'' mode; don't print out the names of the files being converted.
  638.  
  639. =back
  640.  
  641. =head1 ENVIRONMENT
  642.  
  643. No environment variables are used.
  644.  
  645. =head1 FILES
  646.  
  647.  /usr/include/*.h
  648.  /usr/include/sys/*.h
  649.  
  650. etc.
  651.  
  652. =head1 AUTHOR
  653.  
  654. Larry Wall
  655.  
  656. =head1 SEE ALSO
  657.  
  658. perl(1)
  659.  
  660. =head1 DIAGNOSTICS
  661.  
  662. The usual warnings if it can't read or write the files involved.
  663.  
  664. =head1 BUGS
  665.  
  666. Doesn't construct the %sizeof array for you.
  667.  
  668. It doesn't handle all C constructs, but it does attempt to isolate
  669. definitions inside evals so that you can get at the definitions
  670. that it can translate.
  671.  
  672. It's only intended as a rough tool.
  673. You may need to dicker with the files produced.
  674.  
  675. Doesn't run with C<use strict>
  676.  
  677. You have to run this program by hand; it's not run as part of the Perl
  678. installation.
  679.  
  680. Doesn't handle complicated expressions built piecemeal, a la:
  681.  
  682.     enum {
  683.         FIRST_VALUE,
  684.         SECOND_VALUE,
  685.     #ifdef ABC
  686.         THIRD_VALUE
  687.     #endif
  688.     };
  689.  
  690. Doesn't necessarily locate all of your C compiler's internally-defined
  691. symbols.
  692.  
  693. =cut
  694.  
  695.